<template>
	<view class="user">
		<view class="top">
			<img src="../../static/image/history.png" alt="">
		</view>
		<view class="content">
			<view class="row" v-for="item in listArr">
				<!-- 使用自定义组件newsbox，在uniapp中可以直接使用自定义组件，不需要手动引入自定义组件 -->
				<newsbox :item="item" @click.native="goDetail(item)"></newsbox>
			</view>
		</view>
		<view class="nohistory" v-if="!listArr.length">
			<image src="../../static/image/nodata.png" mode="widthFix"></image>
			<view class="text">
				暂无浏览记录
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				listArr:[]
			}
		},
		onLoad(){
			this.getData()
		},
		methods: {
			// 子组件newsbox的点击事件回调
			goDetail(item) {
				// 跳转到新闻详情页，显示detail组件
				uni.navigateTo({
					url: `/pages/detail/detail?cid=${item.classid}&id=${item.id}`
				})
			},
			getData(){
				// 从本地存储中获取指定数据
				let hisArr = uni.getStorageSync("historyArr") || []
				this.listArr = hisArr
			}
		}
	}
</script>

<style lang="scss">
	.user {
		.top {
			background: #f8f8f8;
			padding: 50rpx 0;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;

			image {
				width: 120rpx;
				height: 120rpx;
			}

			.text {
				font-size: 38rpx;
				padding-top: 20rpx;
			}
		}

		.content {
			padding: 30rpx;

			.row {
				padding: 20rpx 0;
				border-bottom: 1rpx #e2e2e2 dotted;
			}
		}

		.noContent {
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;

			image {
				width: 500rpx;
			}

			.text {
				font-size: 30rpx;
				color: #888;
			}
		}
		.nohistory{
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			
			image {
				width: 400rpx;
			}
			.text{
				font-size: 26rpx;
				color: #888;
			}
		}
	}
</style>